var dialog = {
    success: function(data){
        swal({
            title: data.message,
            text: data.info,
            type: "success",

        },function(){
            window.location=data.url
        })
    },
    onesuccess: function(data){
        swal({
            title: data.message,
            text: data.info,
            type: "success",

        })
    },
    error : function(data){
        swal({
            title: data.message,
            text: data.info,
            type: "error"
        });
    }
}

    $('.attr-del').click(function(){
        var id = $(this).attr('attr-id');
        var message = $(this).attr('attr-message');
        var url = SCOPE.url_del;
        var $this = $(this).parents('tr');
        swal({
                title: "您确定要删除"+message+"?",
                text: "删除后将无法恢复！",
                type: "error",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                closeOnConfirm: false},
                function(){
                    $.post(url,{'id':id},function(msg){
                        if(msg.status == 1){
                            swal(msg.message,msg.info, "success");
                            $this.remove();
                        }else{
                            swal(msg.message,msg.info, "error");
                        }
                    },'json')
                })

    });

    function accretion(data){
        data.ajaxSubmit({
            url:SCOPE.url_form,
            type:'post',
            dataType:'json',
            success : function (msg) {
                if(msg.status==1){
                    dialog.success(msg)
                }else{
                    dialog.error(msg)
                }
            },
            error:function(XmlHttpRequest, textStatus, errorThrown){
                alert(textStatus);
            }
        })

    }
function modification(data){
    data.ajaxSubmit({
        url:SCOPE.url_edit,
        type:'post',
        dataType:'json',
        success : function (msg) {
            if(msg.status==1){
                dialog.success(msg)
            }else{
                dialog.error(msg)
            }
        },
        error:function(XmlHttpRequest, textStatus, errorThrown){
            alert(textStatus);
        }
    })
}

$('.attr-sort').change(function(){
    var id = $(this).attr('attr-id');
    var value = $(this).val();
    var $this = $(this);
    $.post(SCOPE.url_sort,{'id':id,'value':value},function(msg){
        if(msg.status==1){
            $this.val(value);
        }else{
            dialog.error(msg)
        }
    },'json')
})


//状态改变
$('.attr-status').on('click',function(){
    var data = {};
    var butt = $(this).parents('ul').prev();
    var status = $(this).attr('attr-status');
    var id= $(this).attr('attr-id');
    var m = $(this).html();
    // var n =butt.attr('class').match(/btn-status-([0-9]{1})/)[1];
    var url = SCOPE.url_status;
    $.get(url,{'status':status,'id':id},function(msg){
        if(1==msg.status){
            if(status==1){
                butt.removeClass('label-warning');
                butt.addClass('label-info');
                butt.html(m+'<span class="caret"></span>');
            }else{
                butt.removeClass('label-info');
                butt.addClass('label-warning');
                butt.html(m+'<span class="caret"></span>');
            }
        }else{
            dialog.error(msg.message);
        }
    },'json');
})



